﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FancyBattles.GameEntities
{
    class Arrow
    {
        public const int ARROW_DAMAGE = 30;
        public const int ARROW_SPEED = 6;
        private static Texture2D redArrow;
        private static Texture2D blueArrow;
        private static List<Arrow> arrowList = new List<Arrow>();
        private Vector2 position;
        private Vector2 direction;
        private BouncingBitch bitch;
        private PlayerIndex player;

        public static Texture2D RedArrow
        {
            set { redArrow = value; }
        }

        public static Texture2D BlueArrow
        {
            set { blueArrow = value; }
        }

        public static List<Arrow> ArrowList
        {
            get { return arrowList; }
        }

        public PlayerIndex Player
        {
            get { return player; }
        }

        public BouncingBitch Bitch
        {
            get { return bitch; }
        }

        public Vector3 Position
        {
            get { return new Vector3(position + direction * 35, 0); }
        }

        public Arrow(Vector2 direction, BouncingBitch bitch)
        {
            this.position = new Vector2(bitch.Position.X + 20, bitch.Position.Y + 20);
            this.player = bitch.Player;
            this.direction = direction;
            this.bitch = bitch;
            arrowList.Add(this);
        }

        public static void ClearArrowList()
        {
            arrowList.Clear();
        }

        public static void DrawArrows(SpriteBatch spriteBatch)
        {
            foreach(Arrow arrow in arrowList)
            {
                if(arrow.player.Equals(PlayerIndex.One))
                {
                    spriteBatch.Draw(blueArrow, new Rectangle((int) arrow.position.X, (int) arrow.position.Y, 64, 64), null, Color.White, (float) Math.Atan2(arrow.direction.Y, arrow.direction.X), new Vector2(0, 32), SpriteEffects.None, 0);
                }
                else
                {
                    spriteBatch.Draw(redArrow, new Rectangle((int)arrow.position.X + 15, (int)arrow.position.Y + 15, 64, 64), null, Color.White, (float)Math.Atan2(arrow.direction.Y, arrow.direction.X), new Vector2(0, 32), SpriteEffects.None, 0);
                }
            }
        }

        public static void UpdateArrows()
        {
            foreach (Arrow arrow in arrowList)
            {
                arrow.position += 5 * arrow.direction;
            }
        }

    }
}
